﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using snake_class;

namespace colorMultiField
{
    public class myConsole
    {
        protected static int origRow;
        protected static int origCol;

        public myConsole()
        {
            origRow = Console.CursorTop;
            origCol = Console.CursorLeft;
        }

        public void ClearConsole()
        {
            Console.Clear();
            origRow = Console.CursorTop;
            origCol = Console.CursorLeft;
        }

        public void writeXY(string target, int x, int y, ConsoleColor color = ConsoleColor.White)
        {
            Console.SetCursorPosition(origCol + x, origRow + y);
            Console.ForegroundColor = color;
            Console.Write(target);
        }

        public void writeField()
        {
            for (int i = 0; i < this.yCount(); i++)
            {
                this.writeXY("@", i, 0, ConsoleColor.DarkGreen);
                this.writeXY("@", i, this.xCount() - 2, ConsoleColor.DarkGreen);
            }
            for (int j = 0; j < this.xCount()-1; j++)
            {
                this.writeXY("@", 0, j, ConsoleColor.DarkGreen);
                this.writeXY("@", this.yCount() - 1, j, ConsoleColor.DarkGreen);
            }
        }

        public void writeSnake(snake mySnake)
        {
            int i = 0;
            this.writeXY("W", mySnake.body[i].x, mySnake.body[i].y, ConsoleColor.Red);
            for (i = 1; i < 200; i++)
            {
                if (mySnake.body[i + 1].x == -1)
                    break;

                this.writeXY("o", mySnake.body[i].x, mySnake.body[i].y, ConsoleColor.Cyan);
            }
            this.writeXY("-", mySnake.body[i].x, mySnake.body[i].y, ConsoleColor.Red);
        }

        public int xCount()
        {
            return Console.WindowHeight;
        }
        public int yCount()
        {
            return Console.WindowWidth;
        }
    }
}
